<?php
	defined('_JEXEC') or die('Restricted access');
    require_once(CUTEENGINE_BASE_COMPONENTS_PATH."base_component_class.php");
	require_once(CUTEENGINE_BASE_COMPONENTS_PATH."base_tag_class.php");
	require_once(CUTEENGINE_BASE_FIELD_PATH."base_field_class.php");
	//
	// t_base_component
	//
	abstract class t_base_display_component extends t_base_component  
	{
		//property 
        // protected
		protected $childs_components_array = array();

		// public
		// C
        public $create_javascript_component = true;
        // D
        public $delayed = false;
		public $delayed_position = -1;
        // F
		const childs_component_parameter_id = 0;
		const childs_component_parameter_visible = 1;
		const childs_component_parameter_last = 2;

		// L
		public $lang = array();
        // M
        public $main_tag = false;
		// N
        public $name = false;
		public $to_logging_tag = false;
        // H
		public $header_script_generator = null; //t_header_script_generator
   		// L
        public $log_tag = null;
        // P 
        public $parts = array();
        // U
        public $use_log = false;
		// S
		public $style_file_name = false;
		// T
		public $to_childs_components_tag = null;
		// method declaration
		// protect
		// C
        protected function create_parts_tags_structure()
        {
            //echo __METHOD__."<BR>";
            //echo "this->parts count: ". count($this->parts)."<BR>";
            foreach ($this->parts As $local_part)
            {
                $local_part->create_tags_structure();
            }
        
        }          
        abstract protected function create_tags_structure();
		
        
       
        // L
        
        // Private
        // Method      
		private function create_parts_from_db($a_query_parameter)
		{
   			//echo __METHOD__ . " - START <br>";
			//print_r(a_query_parameter);
            $local_id = $a_query_parameter->sql_values[t_cuteengine_component::main_query_component_id];
			$local_continue = true;
			while(($local_continue) && ($local_id == $this->id))
			{
				//echo "<BR> " . __METHOD__ . " - local_id($local_id) == this->id($this->id) <BR>";
				$local_function_name = 'add_part_from_current_db_record';
				$local_part_id = $a_query_parameter->sql_values[t_cuteengine_component::main_query_field_name_part_id];
                if (isset($local_part_id))
					$a_query_parameter->execute_function_from_current_record($this,$local_function_name);
                if ($local_continue = $a_query_parameter->next_record())
					$local_id = $a_query_parameter->sql_values[t_cuteengine_component::main_query_component_id];
            }
            //echo __METHOD__ . " - END <br>";
        }
        // Private
        // Method
		private function create_javascript_initialization_component()
		{   
            
            global $g_javascript_namespace;
            // CLASS $this->base_javascript_component_name
            $g_javascript_namespace->header_script_generator->add_class_as_first_class(
				$this->base_javascript_component_name(),'','');
            $g_javascript_namespace->header_script_generator->add_cuteengine_component_as_property_of_a_class(
                t_content_loader,"content_loader",get_class($this),$this->name,'','0');	

    
            // method
            // C
            $g_javascript_namespace->header_script_generator->add_method_to_a_class_with_content($this->base_javascript_component_name(),
                "create_properties","a_object_prototype,a_property_name,a_class_creation_function,a_parent_componet_name,a_log_componet_name,a_id,a_events_array","
			var local_arg = [];
			var local_array_match = /[\[].*[\]]/ig;
			for(var i = 7; i<arguments.length; i++) 
				if ((typeof(arguments[i]) == 'string') && (!(arguments[i].match(local_array_match))))
					local_arg.push(\"'\"+arguments[i].addslashes()+\"'\");
				else
					local_arg.push(arguments[i]);
            var local_arg_str = local_arg.toString();
            if (local_arg_str != '')
                local_arg_str = ','+local_arg_str;
				
			var local_ce = window.cuteengine;
            if (local_ce == undefined)
				local_ce = this;
				
			eval('a_object_prototype[a_property_name] = new a_class_creation_function(local_ce,a_property_name,a_parent_componet_name,a_log_componet_name,a_id,a_events_array'+local_arg_str+')');");
  
            // H
            $g_javascript_namespace->header_script_generator->add_method_to_a_class_with_content($this->base_javascript_component_name(),
                "html_tag","a_component_name",/*"
			local_return = this.html_tag_array[a_component_name];
            if (local_return == undefined)
            {
                this.set_html_tag_as_property(this,a_component_name,a_component_name);
                local_return = this.html_tag_array[a_component_name];
            }
	return local_return*/"
            return this.set_html_tag_as_property(this,a_component_name,a_component_name);
			");        
            // S
            $g_javascript_namespace->header_script_generator->add_method_to_a_class_with_content($this->base_javascript_component_name(),
                "set_html_tag_as_property","a_object,a_html_tag_name,a_property_name","
            var local_tag = document.getElementById(a_html_tag_name);
			if ((local_tag != null) && (local_tag.ce_extension == undefined))
				local_tag.ce_extension = new t_ce_extension_class(local_tag);
			return local_tag");
            //a_object.html_tag_array[a_property_name] = local_tag;");
            //
			//CLASS get_class($this)
            $g_javascript_namespace->header_script_generator->add_class(
				get_class($this),'a_cuteengine,a_name,a_parent_id,a_log_componet_name,a_id',$this->base_javascript_component_name());
			$g_javascript_namespace->header_script_generator->add_property_to_a_class(
                get_class($this),'log_componet_name',"a_log_componet_name",false); 	
			$this->delayed_position =
				$g_javascript_namespace->header_script_generator->set_delayed_state(get_class($this),$this->delayed);	
            //echo "this->delayed_position: $this->delayed_position <br>";
			// method
            // S
            $g_javascript_namespace->header_script_generator->add_method_to_a_class_with_content(
                get_class($this),"set_changed_tag","a_tag","
            var local_start_count = this.changed_tags.length;
			if (this.changed_tags.exists(a_tag) == false)
			{
				this.changed_tags.push(a_tag);
                local_count = this.changed_tags.length;
			}	
			return ((local_count == 1) && (local_start_count == 0));
            ");
            // property
            // C
			$g_javascript_namespace->header_script_generator->add_property_to_a_class(
                get_class($this),'cuteengine','a_cuteengine',false);
            $g_javascript_namespace->header_script_generator->add_property_to_a_class(
                get_class($this),'changed_tags','[]',false);	
            // H    
            $g_javascript_namespace->header_script_generator->add_property_to_a_class(
                $this->base_javascript_component_name(), "html_tag_array","[]");
            // I
			$g_javascript_namespace->header_script_generator->add_property_to_a_class(
                get_class($this),'id',"a_id",false);
			// N
			$g_javascript_namespace->header_script_generator->add_property_to_a_class(
                get_class($this),'name',"a_name",false);	
				
			// P
            $g_javascript_namespace->header_script_generator->add_property_to_a_class(
				get_class($this),'parent_id','a_parent_id');	
                


		}		
		
        // public
        public function __construct( $a_cuteengine_component,$a_query_parameter ) 
		{
        /*
                        Retrives the component name from database and sets default_method property as add_component_to_page_structure . 
                        Initializes the method uesed to create the javascript functions on html page by calling create_javascript_initialization_component method. 
                        Creates all the parts, internal and external  
		   Creates the tags structure by calling the create_tags_structure method
                  */      
            global $g_javascript_namespace;
            global $g_ambient_namespace;
            global $g_cuteengine;
			global $g_strings_utility_namespace;
			global $g_url_parameters_namespace;
            //echo __METHOD__ . "<br>";
			try
            {
                parent::__construct($a_cuteengine_component);
				$g_ambient_namespace->load_language($this);
                $this->name = $this->get_main_query_parameter_value(t_cuteengine_component::main_query_component_name);
               // echo "this->name: $this->name<br>"; 
				$this->delayed = $this->get_main_query_parameter_value(t_cuteengine_component::main_query_delays_the_creation_of_javascript);
				//echo 'this->get_main_query_parameter_value(t_cuteengine_component::main_query_childs_components): '.$this->get_main_query_parameter_value(t_cuteengine_component::main_query_childs_components)."<br>";
				$this->childs_components_array = json_decode($this->get_main_query_parameter_value(t_cuteengine_component::main_query_childs_components));
                //print_r($this->childs_components_array);
				foreach($this->childs_components_array as $local_index => $local_component_difinition)
				{
					if (count($local_component_difinition) == (self::childs_component_parameter_last))
					{
						
						$g_cuteengine->add_CEC_into_finally_CECs($local_component_difinition[self::childs_component_parameter_id]);
							
					}	
					else
						throw new Exception('Error creating object class '.get_class($this).
							" named: \"$this->name\". Wrong required CHILDS COMPONENTS definition for child component number: $local_index were specified(defined ".
							(count($local_component_difinition)) . ' fileds instead of '.
							(self::childs_component_parameter_last).').');	
				}
				//echo "this->delayed: $this->delayed - ";
                //echo "this->name: $this->name <br>";
                $this->default_method = 'add_component_to_page_structure';
                //
                $this->header_script_generator = new t_header_script_generator;
                //javascript
                if ($this->create_javascript_component === true)
                {
                    $this->create_javascript_initialization_component();			
                    
                }
                // links
                $g_javascript_namespace->header_script_generator->add_link(
                    $g_ambient_namespace->get_absolute_web_style_file_path(),
                    $g_ambient_namespace->get_absolute_style_file_path(),
                    $this->get_style_file_name_for_the_class().".css");
                // tags structure
                //echo "create_tags_structure PRIMA<BR>";
                //
                $this->create_internal_parts();
                if (isset($a_query_parameter))
                {
                   
				   // echo "INIT INTERNAL PARS<br>";
					$this->create_parts_from_db($a_query_parameter);
					$local_first_part = reset($this->parts);
					if ($local_first_part)
					{
						// more_fields from db
						//echo "ID: $this->id - local_more_fields:".$this->get_main_query_parameter_value(t_cuteengine_component::main_query_component_more_fields)."<br>";
		/* *** TO VERIFY *** */				/*$local_first_part->import_fields_array_from_string(
		/* *** TO VERIFY *** */					/*$this->get_main_query_parameter_value(t_cuteengine_component::main_query_component_more_fields),false);*/
					}		
					// more_actions from db
					
					$local_more_actions = $g_url_parameters_namespace->add_argument_value_to_str(0,$this->get_main_query_parameter_value(t_cuteengine_component::main_query_component_more_actions),4);
					//echo "local_more_actions:$local_more_actions<br>";
					$local_more_actions_array = $g_strings_utility_namespace->check_json_string_parameters($this,$this->name,'',
						$local_more_actions, -1,"MORE ACTIONS",true);
					foreach ($local_more_actions_array as $local_action_index => $local_action_str) 
					{
						t_base_action::create_action_from_string($this,null,$local_action_str);
					}
					
                   // echo "create_parts_from_db OK <br>";
                } 
				$this->to_logging_tag = new t_base_tag(t_base_tag_type::btt_div,
					$this->name."_to_logging");
				$this->to_logging_tag->include_child_str = true;
			
                $this->create_tags_structure();
                //echo "create_tags_structure OK <br>";
                $this->create_parts_tags_structure();
                
                //echo "create_parts_tags_structure OK<BR>";
            }
            catch (Exception $e) 
            {
               echo $e->getMessage();
               // $g_cuteengine->log->add_log_error($e->getMessage());
            }     
		}
/*		public function __call($name, $arguments) 
		{
			// included file
			$local_return = null;
			$local_file_name = get_class($this) . "_$name";
			$local_component_path = CUTEENGINE_COMPONENTS_PATH . substr(get_class($this),2,strlen(get_class($this))) . DIRECTORY_SEPARATOR  ;
			$this->log->add_log_on_page("$local_component_path$local_file_name.php");
			if (file_exists(CUTEENGINE_PATH_CUSTOM_FILES . $local_file_name . "_" . $this->id . ".php"))
				require(CUTEENGINE_PATH_CUSTOM_FILES . $local_file_name . "_" . $this->id . ".php");
			else if (file_exists("$local_component_path$local_file_name.php"))
				require("$local_component_path$local_file_name.php");
			else
				$this->log->add_log_on_page("files '$local_file_name.php' and '$local_file_name" . "_" . $this->id . ".php' not found.");     
			//echo "local_return: $local_return <br>";	
			return $local_return;
		}	*/	
        // A
        public function add_component_to_page_structure()
        {
        /*
                        Calls the $g_cuteengine->add_component_to_page_structure method.
                  */
           // echo "add_component_to_page_structure: $this->id <br>";
			global $g_cuteengine;
          //  echo "sql_values: ";
			//print_r($this->main_query_parameter->sql_values);
			//$g_cuteengine->add_new_CEC($this->main_query_parameter->sql_values);
			$g_cuteengine->add_component_to_page_structure($this->id);
        }
        public function add_new_part($a_part_id,$a_part_order,$a_part_type,$a_part_common_parameters,$a_part_specific_parameters,$a_specific_fields_string,$a_required_actions_string,$a_part_enabled)
        {
		/*
                        Adds a new part.
                  */ 
			global $g_ambient_namespace;
			global $g_url_parameters_namespace;
			//echo "a_part_id:$a_part_id<br>";
			//echo "a_part_order:$a_part_order<br>";
			//echo "a_part_type:$a_part_type<br>";
			//echo "a_part_common_parameters:$a_part_common_parameters<br>";
			//echo "a_part_specific_parameters:$a_part_specific_parameters<br>";
            //echo "a_specific_fields_string:$a_specific_fields_string<br>";
			//echo "a_required_actions_string:$a_required_actions_string<br>";
			//echo "a_part_enabled:$a_part_enabled<br>";
			
			$local_file_name = substr($a_part_type,2,strlen($a_part_type));
            $local_part_path = CUTEENGINE_PARTS_PATH. $local_file_name . DIRECTORY_SEPARATOR  ;
            //echo "$local_part_path$local_file_name.php <br>";
            
			if (!array_key_exists($a_part_id,$this->parts))
            {
                //echo "FileName: $local_part_path$local_file_name.php <br>";
                if (file_exists("$local_part_path$local_file_name.php"))
                {
                    
                    try
                    {
                        if (trim($a_specific_fields_string) != '')
							$local_main_query_component_more_fields = substr($this->get_main_query_parameter_value(t_cuteengine_component::main_query_component_more_fields),1);
						else
						    $local_main_query_component_more_fields = $this->get_main_query_parameter_value(t_cuteengine_component::main_query_component_more_fields);
						require_once("$local_part_path$local_file_name.php"); 
                        $g_ambient_namespace->autoload_content = 'parts_content';

                        $local_main_query_component_more_fields = $g_url_parameters_namespace->add_argument_value_to_str(0,$local_main_query_component_more_fields,4);
						//echo "local_main_query_component_more_fields:$local_main_query_component_more_fields<br>";
						$local_part = new $a_part_type($this,$a_part_id,$a_part_order,$a_part_type,
                            $a_part_common_parameters,$a_part_specific_parameters,$a_specific_fields_string.$local_main_query_component_more_fields,$a_required_actions_string,$a_part_enabled);
                       // echo "local_part->get_part_name:" . $local_part->get_part_name()."<br>";
                        $this->parts[$local_part->get_part_name()] = $local_part;
                    }    
                    catch (Exception $e) 
                    {
                       echo "ERROR: " . $e->getMessage();
                       // $g_cuteengine->log->add_log_error($e->getMessage());
                    }                         
                    
                }
                else
                {
                    throw new Exception("Error creating component: $this->name (".get_class($this)."). Part class file \"$local_file_name\" not found"); 
                }
            }
            else
            {
                throw new Exception("Error creating component: $this->name (".get_class($this)."). Part id \"$a_part_id\" already exist."); 
            }
            return $local_part; 
        }
		public function add_part_from_current_db_record($a_query_parameter)
		{
            //echo __METHOD__ . " - START <br>";
            $local_part = $this->add_new_part(
				$a_query_parameter->get_parameter_value(
                    t_cuteengine_component::main_query_field_name_part_id,
                    t_cuteengine_component::main_query_parameter_position_part_id),
				$a_query_parameter->get_parameter_value(
                    t_cuteengine_component::main_query_field_name_part_order,
                    t_cuteengine_component::main_query_parameter_position_order),
                $a_query_parameter->get_parameter_value(
                    t_cuteengine_component::main_query_field_name_part_type,
                    t_cuteengine_component::main_query_parameter_position_part_type),
				$a_query_parameter->get_parameter_value(
                    t_cuteengine_component::main_query_field_name_part_common_parameters,
                    t_cuteengine_component::main_query_parameter_position_part_common_parameters),
				$a_query_parameter->get_parameter_value(
                    t_cuteengine_component::main_query_field_name_part_specific_parameters,
                    t_cuteengine_component::main_query_parameter_position_part_specific_parameters),	
				$a_query_parameter->get_parameter_value(
                    t_cuteengine_component::main_query_field_name_part_specific_fields,
                    t_cuteengine_component::main_query_parameter_position_part_specific_fields),
				$a_query_parameter->get_parameter_value(
                    t_cuteengine_component::main_query_field_name_part_required_actions,
                    t_cuteengine_component::main_query_parameter_position_part_required_actions),					
				$a_query_parameter->get_parameter_value(
                    t_cuteengine_component::main_query_field_name_part_enabled,
                    t_cuteengine_component::main_query_parameter_position_part_enabled));     
               
        //    echo __METHOD__ . " - END <br>";
        }
		// B
        public static function base_javascript_component_name() 
		{
            //echo "base_javascript_component_name<br>";
            global $g_javascript_namespace;
            if ($g_javascript_namespace->optimize === true)    
                return 'b_c_c';
            else    
                return 'base_component_class';
		}
        // C
        public function create_internal_parts()
        {
            
        }
        
		// E
        public function export_style_sheet_to_file($a_file_name,$a_style_sheet,$a_force_overwrite) 
		{
			
            global $g_ambient_namespace;
            global $g_cuteengine;
            //
            $local_file_name = $g_ambient_namespace->get_absolute_style_file_path() .$this->get_style_file_name_for_the_class(). ".css"; /*$g_ambient_namespace->get_file_browser_version_name(
                $g_ambient_namespace->get_absolute_style_file_path(),
                $a_file_name,".css");*/
			//echo "local_file_name:$local_file_name - a_force_overwrite: $a_force_overwrite<br>";	
            $local_result = false;
            //
	        try
            {
                if (($a_force_overwrite === true) || (! file_exists($local_file_name)))
                {
                    // GENERAL CSS FILE
                    $local_file_handle = fopen($local_file_name, 'wb');
                    try
                    {
                        $local_size = strlen($a_style_sheet);
						//echo "a_style_sheet:$a_style_sheet<br>";
                        $local_wrote_size = fwrite($local_file_handle,$a_style_sheet);
                        if ($local_size !== $local_wrote_size)
                        {
                            $g_cuteengine->log->add_log_error("Warning, it was write only $local_wrote_size bytes of $local_size");
                        }
                        $local_result = true;
                    }    
                    catch (Exception $e) 
                    {
                        $g_cuteengine->log->add_log_error($e->getMessage());
                    } 
                    fclose($local_file_handle);
                }
            }
            catch (Exception $e) 
            {
                $g_cuteengine->log->add_log_error($e->getMessage());
            } 
            return $local_result;
		}		
		// F
		public function finalize_creation_component()
        {   
			global $g_cuteengine;
			parent::finalize_creation_component();
			foreach($this->childs_components_array as $local_index => $local_component_difinition)
			{
				$local_child_component = $g_cuteengine->get_cuteengine_component_by_id($local_component_difinition[self::childs_component_parameter_id])->page_component;
				//echo "local_child_component->name: $local_child_component->name <br>";
				//print_r($local_child_component);	
				$local_tag = $local_child_component->main_tag;
							
				if (strtoupper($local_component_difinition[self::childs_component_parameter_visible]) == 'TRUE')
				{
					//$local_tag->add_style_property('display','');
				}
				else
				{
					$local_tag->add_style_property('display','none');
				}	
			}
			foreach ($this->parts As $local_part)
            {			
				$local_part->finalize_creation_part();
			}
			
        }
		// G
		public function generate_component_scripts(&$a_style_sheet_destination,
			&$a_javascript_functions_destination)
		{
			//echo "a_style_sheet_destination: $a_style_sheet_destination<br>-----------------------------------------------------------------------------<br>"; 
            // Generates main_tag script script and its childs script;
			$local_style_sheet_destination = '';
            //echo "CSS $this->name: $local_style_sheet_destination <BR>";    
            //$this->generate_component_scripts($local_style_sheet_destination,
				//$a_javascript_functions_destination);

            $this->main_tag->generate_component_scripts($local_style_sheet_destination,
				$a_javascript_functions_destination);
            //echo "CSS $this->name 2: $local_style_sheet_destination <BR>";    
			$this->export_style_sheet_to_file($this->get_style_file_name_for_the_class(),
                $local_style_sheet_destination,false);
                
		}
		public function generate_html_code($a_child_str_to_include = '')
		{
			global $g_cuteengine;
			//echo "this->name: $this->name - a_child_str_to_include: $a_child_str_to_include <BR>FINE ECHO";
			$local_login_field = $g_cuteengine->login_field;
			$local_is_there_login_field = (isset($local_login_field));
			if (($local_is_there_login_field) && (! $local_login_field->is_component_to_render($this)))
			{
				//echo "NO LOGGED FOR COMPONENT ID: ".$this->id;
				return $this->to_logging_tag->generate_html_code();
			}	
				
			
			//echo "a_child_str_to_include: $a_child_str_to_include<br><br><br><br>";
			if (isset($this->to_childs_components_tag))
			{
				//echo "this->to_childs_components_tag->name: ".$this->to_childs_components_tag->name."<br>";
				//echo "a_child_str_to_include: $a_child_str_to_include<br>";
				$this->to_childs_components_tag->set_text_to_include($a_child_str_to_include);
				//echo "this->main_tag->generate_html_code: ".$this->main_tag->generate_html_code()."<br>";
				//print_r($this->main_tag);
				//print_r($this->to_childs_components_tag);
				$local_main_tag_script = $this->main_tag->generate_html_code();
			}
			else
				$local_main_tag_script = $this->main_tag->generate_html_code($a_child_str_to_include);
			//echo "local_main_tag_script: $local_main_tag_script<br>";
			if ((!$local_is_there_login_field) || (! $local_login_field->has_login_request($this)))
				return $local_main_tag_script;
			else
			{
				
				return $this->to_logging_tag->generate_html_code($local_main_tag_script);
			}
			
				
			
		}
		public function generate_style_sheet_script(&$a_destination)
		{
			//echo "generate_style_sheet_script";
			global $g_ambient_namespace;
			//
            $local_style_sheet = '';
			/*if (! $g_ambient_namespace->edit_mode)
				$local_style_sheet = $this->get_main_query_parameter_value(
					t_cuteengine_component::main_query_component_stylesheet);
			else		
				$local_style_sheet = $this->get_main_query_parameter_value(
					t_cuteengine_component::main_query_component_stylesheet_on_edit_page);*/
            $this->main_tag->generate_style_sheet_script($a_destination);
			//
			$a_destination .= $local_style_sheet;
		}
		/*public function generate_functions_script(&$a_destination)
		{
			//echo "generate_style_sheet_script";
            $this->main_tag->generate_functions_script($a_destination);
		}*/
        public function get_action_name()
        {
        }
        public function get_hashed_action_name()
        {
            return md5($this->get_action_name());
        }
		public function get_lang_count()
        {
            return (count($this->lang));
        }
		public function get_log_tag_name()
		{
            
			$local_tag_name = $this->name.'_log_component';
			return $local_tag_name;
        }

		public function get_specific_event_query($a_event_type)		
		{
			$local_return = '';
			if (($a_event_type == t_base_field::field_event_type_on_edit) || ($a_event_type == t_base_field::field_event_type_on_selected))
				$local_return = $this->get_specific_parameters_position_update_query();
			else if($a_event_type == t_base_field::field_event_type_on_insert)
				$local_return = $this->get_specific_parameters_position_insert_query();
			else if($a_event_type == t_base_field::field_event_type_on_delete)
				$local_return = $this->get_specific_parameters_position_delete_query();
			return 	$local_return;
		}
		public function get_first_part()
        {
            reset($this->parts);
			return current($this->parts);
        }
        public function get_specific_parameters_position_selection_query()
        {
            return ''; 
        }        
	    public function get_specific_parameters_position_selection_query_conditions()
        {
            return '';
        } 
	    public function get_specific_parameters_position_selection_query_fields_to_order()
        {
            return '';
        } 
        public function get_specific_parameters_position_update_query()
        {
            return ''; 
        } 
        public function get_specific_parameters_position_insert_query()
        {
            return ''; 
        } 
        public function get_specific_parameters_position_delete_query()
        {
            return ''; 
        } 	
        public function get_start_field_name()
        {
            return '';
        }
        
        public function get_style_file_name_for_the_class()
        {
            global $g_ambient_namespace;
			if ($this->style_file_name === false)
			{
				$local_file_name = $g_ambient_namespace->get_file_browser_version_name(
					$g_ambient_namespace->get_absolute_style_file_path(),
					$this->name,".css");
				$this->style_file_name = basename($local_file_name, ".css");	
			}		
			return $this->style_file_name;
        }
        public function get_style_file_name_for_the_component()
        {
            return $this->name;
        }
        public function get_style_from_file($a_file_name) 
		{
			global $g_ambient_namespace;
            global $g_cuteengine;
            //
            $local_file_name =  $g_ambient_namespace->get_absolute_style_file_path() .$this->get_style_file_name_for_the_class(). ".css";/*$g_ambient_namespace->get_file_browser_version_name(
                $g_ambient_namespace->get_absolute_style_file_path(),
                $a_file_name,".css");*/
			
            $g_cuteengine->log->add_log_error($a_file_name);
            $local_result = '';
            //
	        try
            {
                if (file_exists($local_file_name))
                {
                    // GENERAL CSS FILE
                    $local_file_handle = fopen($local_file_name, 'rb');
                    try
                    {
                        $local_file_size = filesize($local_file_name);
                        $local_result = fread($local_file_handle, $local_file_size);
                        //echo "local_result:$local_result<br>";
                        $g_cuteengine->log->add_log_error($local_result);
                        $local_size = strlen($local_result);
                        if ($local_size !== $local_file_size)
                        {
                            $g_cuteengine->log->add_log_error("Warning, it was read only $local_size bytes of $local_file_size");
                        }                        
                    }    
                    catch (Exception $e) 
                    {
                        $g_cuteengine->log->add_log_error($e->getMessage());
                    } 
                    fclose($local_file_handle);
                }
            }
            catch (Exception $e) 
            {
                $g_cuteengine->log->add_log_error($e->getMessage());
            } 
            return $local_result;
			
		}		
		public function get_to_login_permission()
		{
			return trim($this->get_main_query_parameter_value(t_cuteengine_component::main_query_component_to_login));
		}
        // P
        public function prepare_scripts()
        {
   			global $g_javascript_namespace;
            global $g_cuteengine;
            $local_parent = $g_cuteengine->get_cuteengine_component_by_id($this->parent_id);
            if (isset($local_parent))
                $local_parent_name = $local_parent->page_component->name;
            else        
                $local_parent_name = '';
            //echo "this->name: $this->name - this->parent_id:$this->parent_id - local_parent_name: $local_parent_name <BR>";    
            //	
            $g_javascript_namespace->header_script_generator->add_cuteengine_component_as_property_of_a_class(
                get_class($this),$this->name,"t_cuteengine",$local_parent_name,$this->get_log_tag_name(),$this->id); 
				
			// events
			if (isset($this->main_tag))
			{
				$this->main_tag->initialize_events_for_a_class($this,
					$g_javascript_namespace->header_script_generator);
			}
        }
		// S
		public function set_to_childs_components_tag($a_to_childs_components_tag)
        {
			//echo "set_to_childs_components_tag OK <br>";
			$this->to_childs_components_tag = $a_to_childs_components_tag;
        }
    }	
?>